# pattern.rb
# Copyright (C) 2004-2006 Akira TAGOH

# Authors:
#   Akira TAGOH  <at@gclab.org>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.


module PRUNE

=begin rdoc

== PRUNE::PATTERN

=end

  module PATTERN
    LETTER = 'A-Za-z'
    DIGIT = '\d'
    # [ ] \ ` _ ^ { | }
    SPECIAL = '\x5B-\x60\x7B-\x7D'
    HEXDIGIT = "#{DIGIT}A-Fa-f"
    IP4ADDR = "#{DIGIT}{1,3}\\.(?:\.[#{DIGIT}]{1,3}){3}"
    NICKNAME = "[#{PATTERN::LETTER}#{PATTERN::SPECIAL}][-#{PATTERN::LETTER}#{PATTERN::DIGIT}#{PATTERN::SPECIAL}]{0,8}"
    ENICKNAME = "[#{PATTERN::LETTER}#{PATTERN::SPECIAL}][-#{PATTERN::LETTER}#{PATTERN::DIGIT}#{PATTERN::SPECIAL}@]+"
    SHORTNAME = "[#{PATTERN::LETTER}#{PATTERN::DIGIT}](?:[#{PATTERN::LETTER}#{PATTERN::DIGIT}-]*[#{PATTERN::LETTER}#{PATTERN::DIGIT}])?"
    # any octet except NUL, CR, LF, " ", :
    NOSPCRLFCL = '\x01-\x09\x0B-\x0C\x0E-\x1F\x21-\x39\x3B-\xFF'
    MIDDLE = "[#{NOSPCRLFCL}][:#{NOSPCRLFCL}]*"
    # any octet except NUL, CR, LF " ", @
    USER = '[\x01-\x09\x0B-\x0C\x0E-\x1F\x21-\x3F\x41-\xFF]+'
    CHANNEL = '\A[#&%!].*'

    Commands = %w(
      CONNECT|DIE|ERROR|PING|PONG|REHASH|RESTART|SERVICE|SQUIT|TRACE|WALLOPS
      ADMIN|AWAY|INFO|LINKS|LIST|LUSERS|MOTD|OPER|PASS|QUIT|SERVLIST|SQUERY|STATS|TIME|USER|USERS|VERSION
      INVITE|ISON|JOIN|KICK|KILL|MODE|NAMES|NICK|NOTICE|PART|PRIVMSG|SUMMON|TOPIC|USERHOST|WHO|WHOIS|WHOWAS
    )
    Responses = %w(
      001,RPL_WELCOME 002,RPL_YOURHOST 003,RPL_CREATED 004,RPL_MYINFO
      005,RPL_BOUNCE
      200,RPL_TRACELINK 201,RPL_TRACECONNECTING 202,RPL_TRACEHANDSHAKE 203,RPL_TRACEUNKNOWN 204,RPL_TRACEOPERATOR
      205,RPL_TRACEUSER 206,RPL_TRACESERVER 207,RPL_TRACESERVICE 208,RPL_TRACENEWTYPE 209,RPL_TRACECLASS
      210,RPL_TRACERECONNECT 211,RPL_STATSLINKINFO 212,RPL_STATSCOMMANDS 213,RPL_STATSCLINE 214,RPL_STATSNLINE
      215,RPL_STATSILINE 216,RPL_STATSKLINE 217,RPL_STATSQLINE 218,RPL_STATSYLINE 219,RPL_ENDOFSTATS
      221,RPL_UMODEIS
      231,RPL_SERVICEINFO 232,RPL_ENDOFSERVICES 233,RPL_SERVICE 234,RPL_SERVLIST 235,RPL_SERVLISTEND 
      240,RPL_STATSVLINE 241,RPL_STATSLLINE 242,RPL_STATSUPTIME 243,RPL_STATSOLINE 244,RPL_STATSHLINE
      246,RPL_STATSPING 247,RPL_STATSBLINE
      250,RPL_STATSDLINE 251,RPL_LUSERCLIENT 252,RPL_LUSEROP 253,RPL_LUSERUNKNOWN 254,RPL_LUSERCHANNELS
      255,RPL_LUSERME 256,RPL_ADMINME 257,RPL_ADMINLOC1 258,RPL_ADMINLOC2 259,RPL_ADMINEMAIL
      261,RPL_TRACELOG 262,RPL_TRACEEND 263,RPL_TRYAGAIN
      265,RPL_LOCALUSERS 266,RPL_GLOBALUSERS
      300,RPL_NONE 301,RPL_AWAY 302,RPL_USERHOST 303,RPL_ISON
      305,RPL_UNAWAY 306,RPL_NOWAWAY
      311,RPL_WHOISUSER 312,RPL_WHOISSERVER 313,RPL_WHOISOPERATOR 314,RPL_WHOWASUSER
      315,RPL_ENDOFWHO 316,RPL_WHOISCHANOP 317,RPL_WHOISIDLE 318,RPL_ENDOFWHOIS 319,RPL_WHOISCHANNELS
      321,RPL_LISTSTART 322,RPL_LIST 323,RPL_LISTEND 324,RPL_CHANNELMODEIS
      325,RPL_UNIQOPIS 329,RPL_CHANNELTIMESTAMP
      331,RPL_NOTOPIC 332,RPL_TOPIC 333,RPL_TOPICTIMESTAMP
      341,RPL_INVITING 342,RPL_SUMMONING
      346,RPL_INVITELIST 347,RPL_ENDOFINVITELIST 348,RPL_EXCEPTLIST 349,RPL_ENDOFEXCEPTLIST
      351,RPL_VERSION 352,RPL_WHOREPLY 353,RPL_NAMREPLY
      361,RPL_KILLDONE 362,RPL_CLOSING 363,RPL_CLOSEEND 364,RPL_LINKS
      365,RPL_ENDOFLINKS 366,RPL_ENDOFNAMES 367,RPL_BANLIST 368,RPL_ENDOFBANLIST 369,RPL_ENDOFWHOWAS
      371,RPL_INFO 372,RPL_MOTD 373,RPL_INFOSTART 374,RPL_ENDOFINFO
      375,RPL_MOTDSTART 376,RPL_ENDOFMOTD
      381,RPL_YOUREOPER 382,RPL_REHASHING 383,RPL_YOURESERVICE 384,RPL_MYPORTIS
      391,RPL_TIME 392,RPL_USERSSTART 393,RPL_USERS 394,RPL_ENDOFUSERS
      395,RPL_NOUSERS
      -1,RPL_CMDACT
      401,ERR_NOSUCHNICK 402,ERR_NOSUCHSERVER 403,ERR_NOSUCHCHANNEL 404,ERR_CANNOTSENDTOCHAN
      405,ERR_TOOMANYCHANNELS 406,ERR_WASNOSUCHNICK 407,ERR_TOOMANYTARGETS 408,ERR_NOSUCHSERVICE 409,ERR_NOORIGIN
      411,ERR_NORECIPIENT 412,ERR_NOTEXTTOSEND 413,ERR_NOTOPLEVEL 414,ERR_WILDTOPLEVEL
      415,ERR_BADMASK
      421,ERR_UNKNOWNCOMMAND 422,ERR_NOMOTD 423,ERR_NOADMININFO 424,ERR_FILEERROR
      431,ERR_NONICKNAMEGIVEN 432,ERR_ERRONEUSNICKNAME 433,ERR_NICKNAMEINUSE
      436,ERR_NICKCOLLISION 437,ERR_UNAVAILRESOURCE
      441,ERR_USERNOTINCHANNEL 442,ERR_NOTONCHANNEL 443,ERR_USERONCHANNEL 444,ERR_NOLOGIN
      445,ERR_SUMMONDISABLED 446,ERR_USERSDISABLED
      451,ERR_NOTREGISTERED
      461,ERR_NEEDMOREPARAMS 462,ERR_ALREADYREGISTRED 463,ERR_NOPERMFORHOST 464,ERR_PASSWDMISMATCH
      465,ERR_YOUREBANNEDCREEP 466,ERR_YOUWILLBEBANNED 467,ERR_KEYSE 468,ERR_INVALIDUSERNAME
      471,ERR_CHANNELISFULL 472,ERR_UNKNOWNMODE 473,ERR_INVITEONLYCHAN 474,ERR_BANNEDFROMCHAN
      475,ERR_BADCHANNELKEY 476,ERR_BADCHANMASK 477,ERR_NOCHANMODES 478,ERR_BANLISTFULL
      481,ERR_NOPRIVILEGES 482,ERR_CHANOPRIVSNEEDED 483,ERR_CANTKILLSERVER 484,ERR_RESTRICTED
      485,ERR_UNIQOPPRIVSNEEDED
      491,ERR_NOOPERHOST 492,ERR_NOSERVICEHOST
      501,ERR_UMODEUNKNOWNFLAG 502,ERR_USERSDONTMATCH
    )
    ResponsesMap = %w(
      PASS,ERR_NEEDMOREPARAMS,ERR_ALREADYREGISTRED,RPL_WELCOME
      NICK,ERR_NONICKNAMEGIVEN,ERR_ERRONEUSNICKNAME,ERR_NICKNAMEINUSE,ERR_NICKCOLLISION,ERR_UNAVAILRESOURCE,ERR_RESTRICTED,RPL_WELCOME
      USER,ERR_NEEDMOREPARAMS,ERR_ALREADYREGISTRED,RPL_WELCOME
      OPER,ERR_NEEDMOREPARAMS,RPL_YOUREOPER,ERR_NOOPERHOST,ERR_PASSWDMISMATCH
      MODE,ERR_NEEDMOREPARAMS,ERR_USERSDONTMATCH,ERR_UMODEUNKNOWNFLAG,RPL_UMODEIS,RPL_CMDACT
      SERVICE,ERR_ALREADYREGISTRED,ERR_NEEDMOREPARAMS,ERR_ERRONEUSNICKNAME,RPL_YOURESERVICE,RPL_YOURHOST,RPL_MYINFO
      QUIT
      SQUIT,ERR_NOPRIVILEGES,ERR_NOSUCHSERVER,ERR_NEEDMOREPARAMS
      JOIN,ERR_NEEDMOREPARAMS,ERR_BANNEDFROMCHAN,ERR_INVITEONLYCHAN,ERR_BADCHANNELKEY,ERR_CHANNELISFULL,ERR_BADCHANMASK,ERR_NOSUCHCHANNEL,ERR_TOOMANYCHANNELS,ERR_TOOMANYTARGETS,ERR_UNAVAILRESOURCE,RPL_CMDACT
      PART,ERR_NEEDMOREPARAMS,ERR_NOSUCHCHANNEL,ERR_NOTONCHANNEL,RPL_CMDACT
      MODE,ERR_NEEDMOREPARAMS,ERR_KEYSET,ERR_NOCHANMODES,ERR_CHANOPRIVSNEEDED,ERR_USERNOTINCHANNEL,ERR_UNKNOWNMODE,RPL_CHANNELMODEIS,RPL_BANLIST,RPL_ENDOFBANLIST,RPL_EXCEPTLIST,RPL_ENDOFEXCEPTLIST,RPL_INVITELIST,RPL_ENDOFINVITELIST,RPL_UNIQOPIS
      TOPIC,ERR_NEEDMOREPARAMS,ERR_NOTONCHANNEL,RPL_NOTOPIC,RPL_TOPIC,ERR_CHANOPRIVSNEEDED,ERR_NOCHANMODES,RPL_CMDACT
      NAMES,ERR_TOOMANYMATCHES,ERR_NOSUCHSERVER,RPL_NAMREPLY,RPL_ENDOFNAMES
      LIST,ERR_TOOMANYMATCHES,ERR_NOSUCHSERVER,RPL_LIST,RPL_LISTEND
      INVITE,ERR_NEEDMOREPARAMS,ERR_NOSUCHNICK,ERR_NOTONCHANNEL,ERR_USERONCHANNEL,ERR_CHANOPRIVSNEEDED,RPL_INVITING,RPL_AWAY
      KICK,ERR_NEEDMOREPARAMS,ERR_NOSUCHCHANNEL,ERR_BADCHANMASK,ERR_CHANOPRIVSNEEDED,ERR_USERNOTINCHANNEL,ERR_NOTONCHANNEL
      PRIVMSG,ERR_NORECIPIENT,ERR_NOTEXTTOSEND,ERR_CANNOTSENDTOCHAN,ERR_NOTOPLEVEL,ERR_WILDTOPLEVEL,ERR_TOOMANYTARGETS,ERR_NOSUCHNICK,RPL_AWAY
      NOTICE
      MOTD,RPL_MOTDSTART,RPL_MOTD,RPL_ENDOFMOTD,ERR_NOMOTD
      LUSERS,RPL_LUSERCLIENT,RPL_LUSEROP,RPL_LUSERUNKOWN,RPL_LUSERCHANNELS,RPL_LUSERME,ERR_NOSUCHSERVER
      VERSION,ERR_NOSUCHSERVER,RPL_VERSION
      STATS,ERR_NOSUCHSERVER,RPL_STATSLINKINFO,RPL_STATSUPTIME,RPL_STATSCOMMANDS,RPL_STATSOLINE,RPL_ENDOFSTATS
      LINKS,ERR_NOSUCHSERVER,RPL_LINKS,RPL_ENDOFLINKS
      TIME,ERR_NOSUCHSERVER,RPL_TIME
      CONNECT,ERR_NOSUCHSERVER,ERR_NOPRIVILEGES,ERR_NEEDMOREPARAMS
      TRACE,ERR_NOSUCHSERVER,RPL_TRACELINK,RPL_TRACECONNECTING,RPL_TRACEHANDSHAKE,RPL_TRACEUNKNOWN,RPL_TRACEOPERATOR,RPL_TRACEUSER,RPL_TRACESERVER,RPL_TRACECLASS,RPL_TRACELOG,RPL_TRACEEND
      ADMIN,ERR_NOSUCHSERVER,RPL_ADMINME,RPL_ADMINLOC1,RPL_ADMINLOC2,RPL_ADMINEMAIL
      INFO,ERR_NOSUCHSERVER,RPL_INFO,RPL_ENDOFINFO
      SERVLIST,RPL_SERVLIST,RPL_SERVLISTEND
      SQUERY,ERR_NORECIPIENT,ERR_NOTEXTTOSEND,ERR_CANNOTSENDTOCHAN,ERR_NOTOPLEVEL,ERR_WILDTOPLEVEL,ERR_TOOMANYTARGETS,ERR_NOSUCHNICK,RPL_AWAY
      WHO,ERR_NOSUCHSERVER,RPL_WHOREPLY,RPL_ENDOFWHO
      WHOIS,ERR_NOSUCHSERVER,ERR_NONICKNAMEGIVEN,RPL_WHOISUSER,RPL_WHOISCHANNELS,RPL_SERVER,RPL_AWAY,RPL_WHOISOPERATOR,RPL_WHOISIDLE,ERR_NOSUCHNICK,RPL_ENDOFWHOIS
      WHOWAS,ERR_NONICKNAMEGIVEN,ERR_WASNOSUCHNICK,RPL_WHOWASUSER,RPL_WHOISSERVER,RPL_ENDOFWHOWAS
      KILL,ERR_NOPRIVILEGES,ERR_NEEDMOREPARAMS,ERR_NOSUCHNICK,ERR_CANTKILLSERVER
      PING,ERR_NOORIGIN,ERR_NOSUCHSERVER,RPL_CMDACT
      PONG,ERR_NOORIGIN,ERR_NOSUCHSERVER
      ERROR
      AWAY,RPL_UNAWAY,RPL_NOWAWAY
      REHASH,RPL_REHASHING,ERR_NOPRIVILEGES
      DIE,ERR_NOPRIVILEGES
      RESTART,ERR_NOPRIVILEGES
      SUMMON,ERR_NORECIPIENT,ERR_FILEERROR,ERR_NOLOGIN,ERR_NOSUCHSERVER,ERR_SUMMONDISABLED,RPL_SUMMONING
      USERS,ERR_NOSUCHSERVER,ERR_FILEERROR,RPL_USERSSTART,RPL_USERS,RPL_NOUSERS,RPL_ENDOFUSERS,ERR_USERSDISABLED
      WALLOPS,ERR_NEEDMOREPARAMS
      USERHOST,RPL_USERHOST,ERR_NEEDMOREPARAMS
      ISON,RPL_ISON,ERR_NEEDMOREPARAMS
    )
  end # module PATTERN

end # module PRUNE
